<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/json_utils.js"></script>
</head>
<script type="text/javascript">
$(document).ready(function() {
	$("#upload_target").hide();
	$("#upload_form").submit(function(e) {
		$("#upload_target").load(function(ex) {
			doc = document.getElementById("upload_target").contentDocument;
			process_response(eval("data=" + doc.body.innerHTML));
		});
	});
});

function process_response(ret) {
	if(ret.code == 'success') {
		$("#showarea").html("<a href='"+ ret.data.furl +"'><img src='" + ret.data.turl + "'/></a>");
	}else{
		error_handler(ret.code);
	}
}
function error_handler(retcode) {
	switch(retcode){
	case 'userId_empty':
		alert("用户ID不能为空");
		break;
	case 'file_empty':
		alert("上传文件不能为空");
		break;
	case 'file_ext_none':
		alert("该文件没有扩展名");
		break;
	case 'file_type_unsupported':
		alert("文件类型不支持");
		break;
	case 'file_too_large':
		alert("文件太大了");
		break;
	}
}
</script>
<body>
<div>
	<form id="upload_form" name="upload_form" action="/image/upload/" enctype="multipart/form-data" method="post" target="upload_target">
		<label for='userId'>UserId：</label><input type='text' id='userId' name='userId'/><br/>
		<label for='file'>文件：</label><input type="file" id="uploader" name="file"/><br/>
		<input type="reset" value="重置"/><input type="submit" value="上传"/>
	</form>
</div>
<iframe id="upload_target" name="upload_target">

</iframe>
<div id="showarea">

</div>

</body>

</html>